import { IFeidaoAiMobile } from '@dfeidao/atom-mobile/interfaces';
import get from '@dfeidao/atom-mobile/local/get';
import remove from '@dfeidao/atom-mobile/local/remove';
import nodejs from '@dfeidao/atom-mobile/msg/nodejs';
import goto from '@dfeidao/atom-mobile/nav/goto';
import render from '@dfeidao/atom-mobile/render/render';
import { Alert } from 'react-native';

export default async function a007(fd: IFeidaoAiMobile, e: Date) {
	// 提交
	const leave_type = get(fd, "leave_type") as string;
	// console.log(leave_type);
	const start_time = get(fd, "start_time") as number;
	// console.log(start_time);
	const end_time = get(fd, "end_time") as number;
	// console.log(end_time);
	const time_length = get(fd, "time_length") as number;
	// console.log(time_length);
	const contents_leave = get(fd, "contents_leave") as string;
	const teacher_no = get(fd, "teacher_no") as string;
	const check_status = "0";
	const productid = get(fd, "productid") as string;
	const teacher_name = get(fd, "teacher_name");
	const submit_status = get(fd, "submit_status") as boolean;

	const ret = await nodejs<{ code: number }>('app-teacher-leave/s001', { contents_leave, teacher_no, time_length, leave_type, start_time, end_time, check_status, teacher_name, productid });
	if (submit_status) {
		if (ret.code === 1) {
			Alert.alert("提交成功");
			remove(fd, "productid");
			remove(fd, "teacher_no");
			remove(fd, "teacher_name");
			remove(fd, "leave_type");
			remove(fd, "time_length");
			remove(fd, "contents_leave");
			remove(fd, "start_time");
			remove(fd, "end_time");
			remove(fd, "submit_status");
			render(fd, { res: "", time1: "", time2: "", time_length: "", qjsy: "" });
			goto(fd, 'app_leave_record', {});
		} else {
			Alert.alert("提交失败，请稍后重试");
		}
	}
}
